package components.editor
{
	import UIFree.uif_component;
	
	import classes.c_urls;
	import classes.c_util;
	
	import MLP.mlp_effectLayer;
	
	import flash.display.BitmapData;
	import flash.display.DisplayObject;
	
	public class c_effectElement extends c_baseElement {
		private var _effect: mlp_effectLayer;
		public function c_effectElement(parent:uif_component, ax:int=0, ay:int=0, awidth:int=0, aheight:int=0) {
			super(parent, ax, ay, awidth, aheight);
		}
		
		override protected function nameClass(): String {
			return locale.EFFECT;
		}
		
		public function get effect(): mlp_effectLayer {
			return _effect;
		}
		
		public function get params(): Object {
			return _effect?_effect.params:null;
		}
		
		public function set params(a_params: Object): void {
			if ((!a_params || !params) || (a_params.id != params.id)) {
				var _tmpEffect: mlp_effectLayer = _effect;
				_effect = createEffectLayer(a_params);
				createImageOwner();
				
				c_util.loadEffect(_effect, c_urls.EFFECTURL + _effect.fileName, function(_effectInterface: Object): void {
					if (_tmpEffect) _tmpEffect.dispose();
					addChild(_effect);
				});
			}
		}
		
		protected function createImageOwner(): void {
			if (owner) _effect.drawBitmapData(owner);
		}
		
		protected function createEffectLayer(a_params: Object): mlp_effectLayer {
			var a_effect: mlp_effectLayer = new mlp_effectLayer(a_params);
			a_effect.width 	= width;
			a_effect.height = height;
			return a_effect;
		}
		
		override public function exportFromMLP(optimize:Boolean=false):DisplayObject {
			var a_effect: mlp_effectLayer = createEffectLayer(params);
			c_util.loadEffect(a_effect, c_urls.EFFECTURL + _effect.fileName);
			a_effect.x = x;
			a_effect.y = y;
			return a_effect;
		}
	}
}